package com.newcapec.servlet;

import com.google.gson.Gson;
import com.newcapec.bean.NewsEntity;
import com.newcapec.service.NewsService;
import com.newcapec.service.impl.NewsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Description:查询校园新闻新闻
 * @Author:yangshupeng
 * @Date: 2022/3/17 20:57
 * @Version:1.0
 */
@WebServlet("/campusNews")
public class QueryCampusNewsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String columnId = req.getParameter("columnId");
        NewsService newsService = new NewsServiceImpl();
        List<NewsEntity> newsEntityList = newsService.queryByColumnId(Integer.parseInt(columnId));
        System.out.println(newsEntityList);

        Gson gson = new Gson();
        resp.getWriter().write(gson.toJson(newsEntityList));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
